// Do file that puts together the BHPS data to be used for the paper "Persistent Inequalities"

clear
set more off

***Start with  the original sample in 1991
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\aindall.dta", clear

***Keep all children (biological and others)
keep if inrange(ahgr2r, 4, 8)

keep ahid apno ahgsex pid aage ahgfno ahgmno afpid ampid

rename pid pid_kid
rename aage age_kid
rename ahgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename afpid pid_father
rename ampid pid_mother


***Add father's age 
rename apno id
rename ahgfno apno
merge m:1 ahid apno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\aindall.dta", keepusing(aage)

drop if _merge==2
drop _merge
rename aage age_father
replace age_father = 1991-age_father
rename apno ahgfno


***Add mother's age 
rename ahgmno apno

merge m:1 ahid apno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\aindall.dta", keepusing(aage)

drop if _merge==2
drop _merge
rename aage age_mother
replace age_mother = 1991-age_mother
rename apno ahgmno



***Drop wave specific id's and order
drop id ahgfno ahgmno
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008 (last survey)
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+17
}
*

gen year = 1991

tempfile bhps1991
save `bhps1991'



************************************************
*Add on new entrants from the surveys 1992-2008*
************************************************
******
*1992*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\bindall.dta", clear

***Keep all children (biological and others)
keep if inrange(bhgr2r, 4, 8)
keep if bnewhy==1 | bnewhy==3
keep bhid bpno bhgsex pid bage bhgfno bhgmno bfpid bmpid

rename pid pid_kid
rename bage age_kid
rename bhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename bfpid pid_father
rename bmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid bhid)
keep if _merge==3
drop _merge
recast long ahid bhid
replace ahid = bhid if ahid==-8
rename pid pid_kid

***Add father's age 
rename bpno id
rename bhgfno bpno
merge m:1 bhid bpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\bindall.dta", keepusing(bage)

drop if _merge==2
drop _merge
rename bage age_father
replace age_father = 1992-age_father
rename bpno bhgfno


***Add mother's age 
rename bhgmno bpno

merge m:1 bhid bpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\bindall.dta", keepusing(bage)

drop if _merge==2
drop _merge
rename bage age_mother
replace age_mother = 1992-age_mother
rename bpno bhgmno


***Drop wave specific id's and order
drop id bhgfno bhgmno bhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+16
}
*

gen year = 1992

tempfile bhps1992
save `bhps1992'




******
*1993*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\cindall.dta", clear

***Keep all children (biological and others)
keep if inrange(chgr2r, 4, 8)
keep if cnewhy==1 | cnewhy==3
keep chid cpno chgsex pid cage chgfno chgmno cfpid cmpid

rename pid pid_kid
rename cage age_kid
rename chgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename cfpid pid_father
rename cmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid chid)
keep if _merge==3
drop _merge
recast long ahid chid
replace ahid = chid if ahid==-8
rename pid pid_kid


***Add father's age 
rename cpno id
rename chgfno cpno
merge m:1 chid cpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\cindall.dta", keepusing(cage)

drop if _merge==2
drop _merge
rename cage age_father
replace age_father = 1993-age_father
rename cpno chgfno


***Add mother's age 
rename chgmno cpno

merge m:1 chid cpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\cindall.dta", keepusing(cage)

drop if _merge==2
drop _merge
rename cage age_mother
replace age_mother = 1993-age_mother
rename cpno chgmno


***Drop wave specific id's and order
drop id chgfno chgmno chid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+15
}
*

gen year = 1993

tempfile bhps1993
save `bhps1993'


******
*1994*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\dindall.dta", clear

***Keep all children (biological and others)
keep if inrange(dhgr2r, 4, 8)
keep if dnewhy==1 | dnewhy==3
keep dhid dpno dhgsex pid dage dhgfno dhgmno dfpid dmpid

rename pid pid_kid
rename dage age_kid
rename dhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename dfpid pid_father
rename dmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid dhid)
keep if _merge==3
drop _merge
recast long ahid dhid
replace ahid = dhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename dpno id
rename dhgfno dpno
merge m:1 dhid dpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\dindall.dta", keepusing(dage)

drop if _merge==2
drop _merge
rename dage age_father
replace age_father = 1994-age_father
rename dpno dhgfno


***Add mother's age 
rename dhgmno dpno

merge m:1 dhid dpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\dindall.dta", keepusing(dage)

drop if _merge==2
drop _merge
rename dage age_mother
replace age_mother = 1994-age_mother
rename dpno dhgmno


***Drop wave specific id's and order
drop id dhgfno dhgmno dhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+14
}
*

gen year = 1994

tempfile bhps1994
save `bhps1994'

******
*1995*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\eindall.dta", clear

***Keep all children (biological and others)
keep if inrange(ehgr2r, 4, 8)
keep if enewhy==1 | enewhy==3
keep ehid epno ehgsex pid eage ehgfno ehgmno efpid empid

rename pid pid_kid
rename eage age_kid
rename ehgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename efpid pid_father
rename empid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid ehid)
keep if _merge==3
drop _merge
recast long ahid ehid
replace ahid = ehid if ahid==-8
rename pid pid_kid


***Add father's age 
rename epno id
rename ehgfno epno
merge m:1 ehid epno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\eindall.dta", keepusing(eage)

drop if _merge==2
drop _merge
rename eage age_father
replace age_father = 1995-age_father
rename epno ehgfno


***Add mother's age 
rename ehgmno epno

merge m:1 ehid epno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\eindall.dta", keepusing(eage)

drop if _merge==2
drop _merge
rename eage age_mother
replace age_mother = 1995-age_mother
rename epno ehgmno


***Drop wave specific id's and order
drop id ehgfno ehgmno ehid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+13
}
*

gen year = 1995

tempfile bhps1995
save `bhps1995'


******
*1996*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\findall.dta", clear

***Keep all children (biological and others)
keep if inrange(fhgr2r, 4, 8)
keep if fnewhy==1 | fnewhy==3
keep fhid fpno fhgsex pid fage fhgfno fhgmno ffpid fmpid

rename pid pid_kid
rename fage age_kid
rename fhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename ffpid pid_father
rename fmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid fhid)
keep if _merge==3
drop _merge
recast long ahid fhid
replace ahid = fhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename fpno id
rename fhgfno fpno
merge m:1 fhid fpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\findall.dta", keepusing(fage)

drop if _merge==2
drop _merge
rename fage age_father
replace age_father = 1996-age_father
rename fpno fhgfno


***Add mother's age 
rename fhgmno fpno

merge m:1 fhid fpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\findall.dta", keepusing(fage)

drop if _merge==2
drop _merge
rename fage age_mother
replace age_mother = 1996-age_mother
rename fpno fhgmno


***Drop wave specific id's and order
drop id fhgfno fhgmno fhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+12
}
*

gen year = 1996

tempfile bhps1996
save `bhps1996'


******
*1997*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\gindall.dta", clear

***Keep all children (biological and others)
keep if inrange(ghgr2r, 4, 8)
keep if gnewhy==1 | gnewhy==3
keep ghid gpno ghgsex pid gage ghgfno ghgmno gfpid gmpid

rename pid pid_kid
rename gage age_kid
rename ghgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename gfpid pid_father
rename gmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid ghid)
keep if _merge==3
drop _merge
recast long ahid ghid
replace ahid = ghid if ahid==-8
rename pid pid_kid


***Add father's age 
rename gpno id
rename ghgfno gpno
merge m:1 ghid gpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\gindall.dta", keepusing(gage)

drop if _merge==2
drop _merge
rename gage age_father
replace age_father = 1997-age_father
rename gpno ghgfno


***Add mother's age 
rename ghgmno gpno

merge m:1 ghid gpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\gindall.dta", keepusing(gage)

drop if _merge==2
drop _merge
rename gage age_mother
replace age_mother = 1997-age_mother
rename gpno ghgmno


***Drop wave specific id's and order
drop id ghgfno ghgmno ghid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+11
}
*

gen year = 1997

tempfile bhps1997
save `bhps1997'


******
*1998*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\hindall.dta", clear

***Keep all children (biological and others)
keep if inrange(hhgr2r, 4, 8)
keep if hnewhy==1 | hnewhy==3
keep hhid hpno hhgsex pid hage hhgfno hhgmno hfpid hmpid

rename pid pid_kid
rename hage age_kid
rename hhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename hfpid pid_father
rename hmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid hhid)
keep if _merge==3
drop _merge
recast long ahid hhid
replace ahid = hhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename hpno id
rename hhgfno hpno
merge m:1 hhid hpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\hindall.dta", keepusing(hage)

drop if _merge==2
drop _merge
rename hage age_father
replace age_father = 1998-age_father
rename hpno hhgfno


***Add mother's age 
rename hhgmno hpno

merge m:1 hhid hpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\hindall.dta", keepusing(hage)

drop if _merge==2
drop _merge
rename hage age_mother
replace age_mother = 1998-age_mother
rename hpno hhgmno


***Drop wave specific id's and order
drop id hhgfno hhgmno hhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+10
}
*

gen year = 1998

tempfile bhps1998
save `bhps1998'


******
*1999*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\iindall.dta", clear

***Keep all children (biological and others)
keep if inrange(ihgr2r, 4, 8)
keep if inewhy==1 | inewhy==3
keep ihid ipno ihgsex pid iage ihgfno ihgmno ifpid impid

rename pid pid_kid
rename iage age_kid
rename ihgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename ifpid pid_father
rename impid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid ihid)
keep if _merge==3
drop _merge
recast long ahid ihid
replace ahid = ihid if ahid==-8
rename pid pid_kid


***Add father's age 
rename ipno id
rename ihgfno ipno
merge m:1 ihid ipno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\iindall.dta", keepusing(iage)

drop if _merge==2
drop _merge
rename iage age_father
replace age_father = 1999-age_father
rename ipno ihgfno


***Add mother's age 
rename ihgmno ipno

merge m:1 ihid ipno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\iindall.dta", keepusing(iage)

drop if _merge==2
drop _merge
rename iage age_mother
replace age_mother = 1999-age_mother
rename ipno ihgmno


***Drop wave specific id's and order
drop id ihgfno ihgmno ihid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+9
}
*

gen year = 1999

tempfile bhps1999
save `bhps1999'


******
*2000*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\jindall.dta", clear

***Keep all children (biological and others)
keep if inrange(jhgr2r, 4, 8)
keep if jnewhy==1 | jnewhy==3
keep jhid jpno jhgsex pid jage jhgfno jhgmno jfpid jmpid

rename pid pid_kid
rename jage age_kid
rename jhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename jfpid pid_father
rename jmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid jhid)
keep if _merge==3
drop _merge
recast long ahid jhid
replace ahid = jhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename jpno id
rename jhgfno jpno
merge m:1 jhid jpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\jindall.dta", keepusing(jage)

drop if _merge==2
drop _merge
rename jage age_father
replace age_father = 2000-age_father
rename jpno jhgfno


***Add mother's age 
rename jhgmno jpno

merge m:1 jhid jpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\jindall.dta", keepusing(jage)

drop if _merge==2
drop _merge
rename jage age_mother
replace age_mother = 2000-age_mother
rename jpno jhgmno


***Drop wave specific id's and order
drop id jhgfno jhgmno jhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+8
}
*

gen year = 2000

tempfile bhps2000
save `bhps2000'


******
*2001*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\kindall.dta", clear

***Keep all children (biological and others)
keep if inrange(khgr2r, 4, 8)
keep if knewhy==1 | knewhy==3
keep khid kpno khgsex pid kage khgfno khgmno kfpid kmpid

rename pid pid_kid
rename kage age_kid
rename khgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename kfpid pid_father
rename kmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid khid)
keep if _merge==3
drop _merge
recast long ahid khid
replace ahid = khid if ahid==-8
rename pid pid_kid


***Add father's age 
rename kpno id
rename khgfno kpno
merge m:1 khid kpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\kindall.dta", keepusing(kage)

drop if _merge==2
drop _merge
rename kage age_father
replace age_father = 2001-age_father
rename kpno khgfno


***Add mother's age 
rename khgmno kpno

merge m:1 khid kpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\kindall.dta", keepusing(kage)

drop if _merge==2
drop _merge
rename kage age_mother
replace age_mother = 2001-age_mother
rename kpno khgmno


***Drop wave specific id's and order
drop id khgfno khgmno khid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+7
}
*

gen year = 2001

tempfile bhps2001
save `bhps2001'


******
*2002*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\lindall.dta", clear

***Keep all children (biological and others)
keep if inrange(lhgr2r, 4, 8)
keep if lnewhy==1 | lnewhy==3
keep lhid lpno lhgsex pid lage lhgfno lhgmno lfpid lmpid

rename pid pid_kid
rename lage age_kid
rename lhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename lfpid pid_father
rename lmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid lhid)
keep if _merge==3
drop _merge
recast long ahid lhid
replace ahid = lhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename lpno id
rename lhgfno lpno
merge m:1 lhid lpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\lindall.dta", keepusing(lage)

drop if _merge==2
drop _merge
rename lage age_father
replace age_father = 2002-age_father
rename lpno lhgfno


***Add mother's age 
rename lhgmno lpno

merge m:1 lhid lpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\lindall.dta", keepusing(lage)

drop if _merge==2
drop _merge
rename lage age_mother
replace age_mother = 2002-age_mother
rename lpno lhgmno


***Drop wave specific id's and order
drop id lhgfno lhgmno lhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+6
}
*

gen year = 2002

tempfile bhps2002
save `bhps2002'


******
*2003*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\mindall.dta", clear

***Keep all children (biological and others)
keep if inrange(mhgr2r, 4, 8)
keep if mnewhy==1 | mnewhy==3
keep mhid mpno mhgsex pid mage mhgfno mhgmno mfpid mmpid

rename pid pid_kid
rename mage age_kid
rename mhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename mfpid pid_father
rename mmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid mhid)
keep if _merge==3
drop _merge
recast long ahid mhid
replace ahid = mhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename mpno id
rename mhgfno mpno
merge m:1 mhid mpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\mindall.dta", keepusing(mage)

drop if _merge==2
drop _merge
rename mage age_father
replace age_father = 2003-age_father
rename mpno mhgfno


***Add mother's age 
rename mhgmno mpno

merge m:1 mhid mpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\mindall.dta", keepusing(mage)

drop if _merge==2
drop _merge
rename mage age_mother
replace age_mother = 2003-age_mother
rename mpno mhgmno


***Drop wave specific id's and order
drop id mhgfno mhgmno mhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+5
}
*

gen year = 2003

tempfile bhps2003
save `bhps2003'


******
*2004*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\nindall.dta", clear

***Keep all children (biological and others)
keep if inrange(nhgr2r, 4, 8)
keep if nnewhy==1 | nnewhy==3
keep nhid npno nhgsex pid nage nhgfno nhgmno nfpid nmpid

rename pid pid_kid
rename nage age_kid
rename nhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename nfpid pid_father
rename nmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid nhid)
keep if _merge==3
drop _merge
recast long ahid nhid
replace ahid = nhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename npno id
rename nhgfno npno
merge m:1 nhid npno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\nindall.dta", keepusing(nage)

drop if _merge==2
drop _merge
rename nage age_father
replace age_father = 2004-age_father
rename npno nhgfno


***Add mother's age 
rename nhgmno npno

merge m:1 nhid npno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\nindall.dta", keepusing(nage)

drop if _merge==2
drop _merge
rename nage age_mother
replace age_mother = 2004-age_mother
rename npno nhgmno


***Drop wave specific id's and order
drop id nhgfno nhgmno nhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+4
}
*

gen year = 2004

tempfile bhps2004
save `bhps2004'


******
*2005*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\oindall.dta", clear

***Keep all children (biological and others)
keep if inrange(ohgr2r, 4, 8)
keep if onewhy==1 | onewhy==3
keep ohid opno ohgsex pid oage ohgfno ohgmno ofpid ompid

rename pid pid_kid
rename oage age_kid
rename ohgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename ofpid pid_father
rename ompid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid ohid)
keep if _merge==3
drop _merge
recast long ahid ohid
replace ahid = ohid if ahid==-8
rename pid pid_kid


***Add father's age 
rename opno id
rename ohgfno opno
merge m:1 ohid opno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\oindall.dta", keepusing(oage)

drop if _merge==2
drop _merge
rename oage age_father
replace age_father = 2005-age_father
rename opno ohgfno


***Add mother's age 
rename ohgmno opno

merge m:1 ohid opno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\oindall.dta", keepusing(oage)

drop if _merge==2
drop _merge
rename oage age_mother
replace age_mother = 2005-age_mother
rename opno ohgmno


***Drop wave specific id's and order
drop id ohgfno ohgmno ohid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+3
}
*

gen year = 2005

tempfile bhps2005
save `bhps2005'


******
*2006*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\pindall.dta", clear

***Keep all children (biological and others)
keep if inrange(phgr2r, 4, 8)
keep if pnewhy==1 | pnewhy==3
keep phid ppno phgsex pid page phgfno phgmno pfpid pmpid

rename pid pid_kid
rename page age_kid
rename phgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename pfpid pid_father
rename pmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid phid)
keep if _merge==3
drop _merge
recast long ahid phid
replace ahid = phid if ahid==-8
rename pid pid_kid


***Add father's age 
rename ppno id
rename phgfno ppno
merge m:1 phid ppno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\pindall.dta", keepusing(page)

drop if _merge==2
drop _merge
rename page age_father
replace age_father = 2006-age_father
rename ppno phgfno


***Add mother's age 
rename phgmno ppno

merge m:1 phid ppno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\pindall.dta", keepusing(page)

drop if _merge==2
drop _merge
rename page age_mother
replace age_mother = 2006-age_mother
rename ppno phgmno


***Drop wave specific id's and order
drop id phgfno phgmno phid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+2
}
*

gen year = 2006

tempfile bhps2006
save `bhps2006'


******
*2007*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\qindall.dta", clear

***Keep all children (biological and others)
keep if inrange(qhgr2r, 4, 8)
keep if qnewhy==1 | qnewhy==3
keep qhid qpno qhgsex pid qage qhgfno qhgmno qfpid qmpid

rename pid pid_kid
rename qage age_kid
rename qhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename qfpid pid_father
rename qmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid qhid)
keep if _merge==3
drop _merge
recast long ahid qhid
replace ahid = qhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename qpno id
rename qhgfno qpno
merge m:1 qhid qpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\qindall.dta", keepusing(qage)

drop if _merge==2
drop _merge
rename qage age_father
replace age_father = 2007-age_father
rename qpno qhgfno


***Add mother's age 
rename qhgmno qpno

merge m:1 qhid qpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\qindall.dta", keepusing(qage)

drop if _merge==2
drop _merge
rename qage age_mother
replace age_mother = 2007-age_mother
rename qpno qhgmno


***Drop wave specific id's and order
drop id qhgfno qhgmno qhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

***Set age to age in 2008
foreach var of varlist age_kid age_father age_mother {
replace `var' = `var'+1
}
*

gen year = 2007

tempfile bhps2007
save `bhps2007'


******
*2008*
******
use "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\rindall.dta", clear

***Keep all children (biological and others)
keep if inrange(rhgr2r, 4, 8)
keep if rnewhy==1 | rnewhy==3
keep rhid rpno rhgsex pid rage rhgfno rhgmno rfpid rmpid

rename pid pid_kid
rename rage age_kid
rename rhgsex sex_kid
replace sex_kid = . if sex_kid==-9
rename rfpid pid_father
rename rmpid pid_mother

***Add household id
rename pid_kid pid
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\xwaveid.dta", keepusing(ahid rhid)
keep if _merge==3
drop _merge
recast long ahid rhid
replace ahid = rhid if ahid==-8
rename pid pid_kid


***Add father's age 
rename rpno id
rename rhgfno rpno
merge m:1 rhid rpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\rindall.dta", keepusing(rage)

drop if _merge==2
drop _merge
rename rage age_father
replace age_father = 2008-age_father
rename rpno rhgfno


***Add mother's age 
rename rhgmno rpno

merge m:1 rhid rpno using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data\rindall.dta", keepusing(rage)

drop if _merge==2
drop _merge
rename rage age_mother
replace age_father = 2008-age_mother
rename rpno rhgmno


***Drop wave specific id's and order
drop id rhgfno rhgmno rhid
order ahid pid_kid pid_father pid_mother


***Generate indicator for youngest parent
egen parent_youngest = rowmin(age_father age_mother)

gen year = 2008

tempfile bhps2008
save `bhps2008'


clear

use `bhps1991', clear
append using `bhps1992'
append using `bhps1993'
append using `bhps1994'
append using `bhps1995'
append using `bhps1996'
append using `bhps1997'
append using `bhps1998'
append using `bhps1999'
append using `bhps2000'
append using `bhps2001'
append using `bhps2002'
append using `bhps2003'
append using `bhps2004'
append using `bhps2005'
append using `bhps2006'
append using `bhps2007'
append using `bhps2008'


***Drop some reentering individuals
gen occ = year*-1+2100
bysort pid_kid: egen nocc = rank(occ), field
keep if nocc==1
drop occ nocc


********************************************
*STACK THREE ELECTIONS AND MERGE TO TURNOUT*
********************************************

*Turnout in 4 general elections --> 1992, 1997, 2001 and 2005
*Use survey response from survey closest after election
*Skip survey during election years (retrospective questions about turnout in last election)

*1992 --> e
*1997 --> h, i, j
*2001 --> l, m, n
*2005 --> p, q, r


*1997
preserve
gen electionyear = 1997

rename pid_kid pid
foreach name in h i j {
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_kid
gen turnout_kid = 0 if hvote7==2
replace turnout_kid = 1 if hvote7==1
replace turnout_kid = 0 if ivote7==2 & turnout_kid==.
replace turnout_kid = 1 if ivote7==1 & turnout_kid==.
replace turnout_kid = 0 if jvote7==2 & turnout_kid==.
replace turnout_kid = 1 if jvote7==1 & turnout_kid==.
drop hvote7 ivote7 jvote7

rename pid_father pid
foreach name in e h i j l m n p q r {
merge m:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_father
gen turnout_father1992 = 0 if evote7==2
replace turnout_father1992 = 1 if evote7==1

gen turnout_father1997 = 0 if hvote7==2
replace turnout_father1997 = 1 if hvote7==1
replace turnout_father1997 = 0 if ivote7==2 & turnout_father1997==.
replace turnout_father1997 = 1 if ivote7==1 & turnout_father1997==.
replace turnout_father1997 = 0 if jvote7==2 & turnout_father1997==.
replace turnout_father1997 = 1 if jvote7==1 & turnout_father1997==.

gen turnout_father2001 = 0 if lvote7==2
replace turnout_father2001 = 1 if lvote7==1
replace turnout_father2001 = 0 if mvote7==2 & turnout_father2001==.
replace turnout_father2001 = 1 if mvote7==1 & turnout_father2001==.
replace turnout_father2001 = 0 if nvote7==2 & turnout_father2001==.
replace turnout_father2001 = 1 if nvote7==1 & turnout_father2001==.

gen turnout_father2005 = 0 if pvote7==2
replace turnout_father2005 = 1 if pvote7==1
replace turnout_father2005 = 0 if qvote7==2 & turnout_father2005==.
replace turnout_father2005 = 1 if qvote7==1 & turnout_father2005==.
replace turnout_father2005 = 0 if rvote7==2 & turnout_father2005==.
replace turnout_father2005 = 1 if rvote7==1 & turnout_father2005==.

drop evote7 hvote7 ivote7 jvote7 lvote7 mvote7 nvote7 pvote7 qvote7 rvote7


rename pid_mother pid
foreach name in e h i j l m n p q r {
merge m:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_mother
gen turnout_mother1992 = 0 if evote7==2
replace turnout_mother1992 = 1 if evote7==1

gen turnout_mother1997 = 0 if hvote7==2
replace turnout_mother1997 = 1 if hvote7==1
replace turnout_mother1997 = 0 if ivote7==2 & turnout_mother1997==.
replace turnout_mother1997 = 1 if ivote7==1 & turnout_mother1997==.
replace turnout_mother1997 = 0 if jvote7==2 & turnout_mother1997==.
replace turnout_mother1997 = 1 if jvote7==1 & turnout_mother1997==.

gen turnout_mother2001 = 0 if lvote7==2
replace turnout_mother2001 = 1 if lvote7==1
replace turnout_mother2001 = 0 if mvote7==2 & turnout_mother2001==.
replace turnout_mother2001 = 1 if mvote7==1 & turnout_mother2001==.
replace turnout_mother2001 = 0 if nvote7==2 & turnout_mother2001==.
replace turnout_mother2001 = 1 if nvote7==1 & turnout_mother2001==.

gen turnout_mother2005 = 0 if pvote7==2
replace turnout_mother2005 = 1 if pvote7==1
replace turnout_mother2005 = 0 if qvote7==2 & turnout_mother2005==.
replace turnout_mother2005 = 1 if qvote7==1 & turnout_mother2005==.
replace turnout_mother2005 = 0 if rvote7==2 & turnout_mother2005==.
replace turnout_mother2005 = 1 if rvote7==1 & turnout_mother2005==.

drop evote7 hvote7 ivote7 jvote7 lvote7 mvote7 nvote7 pvote7 qvote7 rvote7

*Cumulative parental turnout indicators
gen turnout_fathercum1 = turnout_father1992
gen turnout_mothercum1 = turnout_mother1992
egen turnout_parentcum1 = rowmean(turnout_father1992 turnout_mother1992)


*Generate child age at election year (from age in 2008)
gen age_kid_election = age_kid-11

tempfile BHPS1997
save `BHPS1997'
restore


*2001
preserve
gen electionyear = 2001

rename pid_kid pid
foreach name in l m n {
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_kid
gen turnout_kid = 0 if lvote7==2
replace turnout_kid = 1 if lvote7==1
replace turnout_kid = 0 if mvote7==2 & turnout_kid==.
replace turnout_kid = 1 if mvote7==1 & turnout_kid==.
replace turnout_kid = 0 if nvote7==2 & turnout_kid==.
replace turnout_kid = 1 if nvote7==1 & turnout_kid==.
drop lvote7 mvote7 nvote7

rename pid_father pid
foreach name in e h i j l m n p q r {
merge m:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_father
gen turnout_father1992 = 0 if evote7==2
replace turnout_father1992 = 1 if evote7==1

gen turnout_father1997 = 0 if hvote7==2
replace turnout_father1997 = 1 if hvote7==1
replace turnout_father1997 = 0 if ivote7==2 & turnout_father1997==.
replace turnout_father1997 = 1 if ivote7==1 & turnout_father1997==.
replace turnout_father1997 = 0 if jvote7==2 & turnout_father1997==.
replace turnout_father1997 = 1 if jvote7==1 & turnout_father1997==.

gen turnout_father2001 = 0 if lvote7==2
replace turnout_father2001 = 1 if lvote7==1
replace turnout_father2001 = 0 if mvote7==2 & turnout_father2001==.
replace turnout_father2001 = 1 if mvote7==1 & turnout_father2001==.
replace turnout_father2001 = 0 if nvote7==2 & turnout_father2001==.
replace turnout_father2001 = 1 if nvote7==1 & turnout_father2001==.

gen turnout_father2005 = 0 if pvote7==2
replace turnout_father2005 = 1 if pvote7==1
replace turnout_father2005 = 0 if qvote7==2 & turnout_father2005==.
replace turnout_father2005 = 1 if qvote7==1 & turnout_father2005==.
replace turnout_father2005 = 0 if rvote7==2 & turnout_father2005==.
replace turnout_father2005 = 1 if rvote7==1 & turnout_father2005==.

drop evote7 hvote7 ivote7 jvote7 lvote7 mvote7 nvote7 pvote7 qvote7 rvote7


rename pid_mother pid
foreach name in e h i j l m n p q r {
merge m:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_mother
gen turnout_mother1992 = 0 if evote7==2
replace turnout_mother1992 = 1 if evote7==1

gen turnout_mother1997 = 0 if hvote7==2
replace turnout_mother1997 = 1 if hvote7==1
replace turnout_mother1997 = 0 if ivote7==2 & turnout_mother1997==.
replace turnout_mother1997 = 1 if ivote7==1 & turnout_mother1997==.
replace turnout_mother1997 = 0 if jvote7==2 & turnout_mother1997==.
replace turnout_mother1997 = 1 if jvote7==1 & turnout_mother1997==.

gen turnout_mother2001 = 0 if lvote7==2
replace turnout_mother2001 = 1 if lvote7==1
replace turnout_mother2001 = 0 if mvote7==2 & turnout_mother2001==.
replace turnout_mother2001 = 1 if mvote7==1 & turnout_mother2001==.
replace turnout_mother2001 = 0 if nvote7==2 & turnout_mother2001==.
replace turnout_mother2001 = 1 if nvote7==1 & turnout_mother2001==.

gen turnout_mother2005 = 0 if pvote7==2
replace turnout_mother2005 = 1 if pvote7==1
replace turnout_mother2005 = 0 if qvote7==2 & turnout_mother2005==.
replace turnout_mother2005 = 1 if qvote7==1 & turnout_mother2005==.
replace turnout_mother2005 = 0 if rvote7==2 & turnout_mother2005==.
replace turnout_mother2005 = 1 if rvote7==1 & turnout_mother2005==.

drop evote7 hvote7 ivote7 jvote7 lvote7 mvote7 nvote7 pvote7 qvote7 rvote7

*Cumulative parental turnout indicators
egen turnout_fathercum1 = rowmean(turnout_father1992 turnout_father1997)
egen turnout_mothercum1 = rowmean(turnout_mother1992 turnout_mother1997)
egen turnout_parentcum1 = rowmean(turnout_father1992 turnout_father1997 turnout_mother1992 turnout_mother1997)


*Generate child age at election year (from age in 2008)
gen age_kid_election = age_kid-7

tempfile BHPS2001
save `BHPS2001'
restore



*2005
preserve
gen electionyear = 2005

rename pid_kid pid
foreach name in p q r {
merge 1:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_kid
gen turnout_kid = 0 if pvote7==2
replace turnout_kid = 1 if pvote7==1
replace turnout_kid = 0 if qvote7==2 & turnout_kid==.
replace turnout_kid = 1 if qvote7==1 & turnout_kid==.
replace turnout_kid = 0 if rvote7==2 & turnout_kid==.
replace turnout_kid = 1 if rvote7==1 & turnout_kid==.
drop pvote7 qvote7 rvote7

rename pid_father pid
foreach name in e h i j l m n p q r {
merge m:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_father
gen turnout_father1992 = 0 if evote7==2
replace turnout_father1992 = 1 if evote7==1

gen turnout_father1997 = 0 if hvote7==2
replace turnout_father1997 = 1 if hvote7==1
replace turnout_father1997 = 0 if ivote7==2 & turnout_father1997==.
replace turnout_father1997 = 1 if ivote7==1 & turnout_father1997==.
replace turnout_father1997 = 0 if jvote7==2 & turnout_father1997==.
replace turnout_father1997 = 1 if jvote7==1 & turnout_father1997==.

gen turnout_father2001 = 0 if lvote7==2
replace turnout_father2001 = 1 if lvote7==1
replace turnout_father2001 = 0 if mvote7==2 & turnout_father2001==.
replace turnout_father2001 = 1 if mvote7==1 & turnout_father2001==.
replace turnout_father2001 = 0 if nvote7==2 & turnout_father2001==.
replace turnout_father2001 = 1 if nvote7==1 & turnout_father2001==.

gen turnout_father2005 = 0 if pvote7==2
replace turnout_father2005 = 1 if pvote7==1
replace turnout_father2005 = 0 if qvote7==2 & turnout_father2005==.
replace turnout_father2005 = 1 if qvote7==1 & turnout_father2005==.
replace turnout_father2005 = 0 if rvote7==2 & turnout_father2005==.
replace turnout_father2005 = 1 if rvote7==1 & turnout_father2005==.

drop evote7 hvote7 ivote7 jvote7 lvote7 mvote7 nvote7 pvote7 qvote7 rvote7


rename pid_mother pid
foreach name in e h i j l m n p q r {
merge m:1 pid using "E:\ProjData\SiblingOrder\OtherSamples\BHPS\Data/`name'indresp.dta", keepusing(`name'vote7)
drop if _merge==2
drop _merge
}
*
rename pid pid_mother
gen turnout_mother1992 = 0 if evote7==2
replace turnout_mother1992 = 1 if evote7==1

gen turnout_mother1997 = 0 if hvote7==2
replace turnout_mother1997 = 1 if hvote7==1
replace turnout_mother1997 = 0 if ivote7==2 & turnout_mother1997==.
replace turnout_mother1997 = 1 if ivote7==1 & turnout_mother1997==.
replace turnout_mother1997 = 0 if jvote7==2 & turnout_mother1997==.
replace turnout_mother1997 = 1 if jvote7==1 & turnout_mother1997==.

gen turnout_mother2001 = 0 if lvote7==2
replace turnout_mother2001 = 1 if lvote7==1
replace turnout_mother2001 = 0 if mvote7==2 & turnout_mother2001==.
replace turnout_mother2001 = 1 if mvote7==1 & turnout_mother2001==.
replace turnout_mother2001 = 0 if nvote7==2 & turnout_mother2001==.
replace turnout_mother2001 = 1 if nvote7==1 & turnout_mother2001==.

gen turnout_mother2005 = 0 if pvote7==2
replace turnout_mother2005 = 1 if pvote7==1
replace turnout_mother2005 = 0 if qvote7==2 & turnout_mother2005==.
replace turnout_mother2005 = 1 if qvote7==1 & turnout_mother2005==.
replace turnout_mother2005 = 0 if rvote7==2 & turnout_mother2005==.
replace turnout_mother2005 = 1 if rvote7==1 & turnout_mother2005==.

drop evote7 hvote7 ivote7 jvote7 lvote7 mvote7 nvote7 pvote7 qvote7 rvote7

*Cumulative parental turnout indicators
egen turnout_fathercum1 = rowmean(turnout_father1992 turnout_father1997 turnout_father2001)
egen turnout_mothercum1 = rowmean(turnout_mother1992 turnout_mother1997 turnout_mother2001)
egen turnout_parentcum1 = rowmean(turnout_father1992 turnout_father1997 turnout_father2001 turnout_mother1992 turnout_mother1997 turnout_mother2001)


*Generate child age at election year (from age in 2008)
gen age_kid_election = age_kid-3

tempfile BHPS2005
save `BHPS2005'
restore




clear

use `BHPS1997', clear
append using `BHPS2001'
append using `BHPS2005'



***Generate some additional variables***
*Indicator for having parental turnout info from at least 3 elections
foreach name in turnout_father turnout_mother {
foreach num in 1992 1997 2001 2005 {
gen occ`name'`num' = 1 if `name'`num'!=.
}
}
foreach name in turnout_father turnout_mother {
egen occ`name'Rost = rowtotal(occ`name'1992 occ`name'1997 occ`name'2001 occ`name'2005)
tab occ`name'Rost
replace occ`name'Rost = . if inrange(occ`name'Rost, 0, 2)
}
egen parent_all = rowmean(occturnout_fatherRost occturnout_motherRost)
replace parent_all = 1 if parent_all!=.
drop occ*


*2 indicators for stability in parental voting
*Variation in stability is due both to over time variation within parent
*and across parent variation at a specific time point
*2nd indicator: Herfindahl's index standardized to 0-1 range
egen parent_consistent = rowmean(turnout_father1992 turnout_mother1992 turnout_father1997 turnout_mother1997 turnout_father2001 turnout_mother2001 turnout_father2005 turnout_mother2005)
replace parent_consistent = 2*abs((parent_consistent-.5))
replace parent_consistent = 0 if parent_consistent!=1 & parent_consistent!=.
egen occ1 = rowmean(turnout_father1992 turnout_mother1992 turnout_father1997 turnout_mother1997 turnout_father2001 turnout_mother2001 turnout_father2005 turnout_mother2005)
gen parent_consistentHI = -1*(1-(occ1^2+(1-occ1)^2))/0.5+1


foreach name in father mother {
foreach level in 1992 1997 2001 2005 {
drop turnout_`name'`level'
}
}
*

*Age of oldest parent
egen age_parent = rowmin(age_father age_mother)

*Rescale age at election and drop all ineligible to vote
replace age_kid_election = age_kid_election-18
drop if age_kid_election<0


*Restrict the age span to correspond to the Swedish samples
keep if inrange(age_kid_election, 0, 32)


*Rename some variables
rename pid_mother famid
rename sex_kid kidfemale
rename turnout_kid turnoutkid
rename turnout_parentcum1 turnoutparentcum
rename age_kid_election kidelectionage
rename parent_consistent parentconsistent
rename parent_consistentHI parentconsistentHI
rename age_parent parentbyear



************
************
***MODELS***
************
************

reg turnoutkid turnoutparentcum i.parentbyear kidfemale i.kidelectionage i.electionyear , cluster(famid)
reg turnoutkid c.turnoutparentcum##c.parentconsistent i.parentbyear##c.parentconsistent c.kidfemale##c.parentconsistent i.kidelectionage##c.parentconsistent i.electionyear##c.parentconsistent, cluster(famid)
reg turnoutkid c.turnoutparentcum##c.parentconsistentHI i.parentbyear##c.parentconsistentHI c.kidfemale##c.parentconsistentHI i.kidelectionage##c.parentconsistentHI i.electionyear##c.parentconsistentHI, cluster(famid)
reg turnoutkid turnoutparentcum c.turnoutparentcum#c.kidelectionage i.parentbyear i.parentbyear#c.kidelectionage kidfemale c.kidfemale#c.kidelectionage i.kidelectionage i.electionyear i.electionyear#c.kidelectionage, cluster(famid)



*Save for pooled sample
keep famid turnoutkid kidfemale parentbyear parentconsistent parentconsistentHI electionyear kidelectionage turnoutparentcum
keep if turnoutkid!=. 
gen sample = 3
gen kidelectionage01 = kidelectionage/32

*drop three strange cases - look up
drop if parentbyear<100

save "E:\ProjData\AdoptionStudy\BHPS\BHPS.dta", replace

